package com.example.mapstructexample.mapper;

import com.example.mapstructexample.bean.Food;
import com.example.mapstructexample.enums.FoodType;
import com.example.mapstructexample.enums.FoodType2;
import com.example.mapstructexample.factory.FoodFactory;
import com.example.mapstructexample.vo.FoodVo;
import org.mapstruct.*;
import org.mapstruct.factory.Mappers;

@Mapper(uses = FoodFactory.class)
public interface FoodMapper {
    //映射器工厂
    FoodMapper INSTANCE = Mappers.getMapper(FoodMapper.class);


    @Mappings({@Mapping(source = "name", target = "name")
            , @Mapping(source = "price", target = "price", numberFormat = "#.00")
            , @Mapping(source = "weight", target = "weight", numberFormat = "#.#E0")
            , @Mapping(source = "productionDate", target = "productionDate", dateFormat = "yyyy-MM-dd HH:mm:ss")
            , @Mapping(source = "foodType", target = "foodType2")})
    FoodVo toFoodVo(Food food);


    @ValueMappings({@ValueMapping(source = "FRUIT", target = "FRUIT2")
            , @ValueMapping(source = "VEGETABLE", target = "VEGETABLE2")
            , @ValueMapping(source = "MEAT", target = "MEAT2")
            , @ValueMapping(source = "STAPLE_FOOD", target = "STAPLE_FOOD2")
    })
    FoodType2 toFoodType2(FoodType foodType);


}
